﻿/*
 Name:		Cokee.ino
 Created:	2023/12/24 下午 12:08:32
 Author:	XiaoY
*/

/*
  Author: Cokee
  Website URL:https://cokee.tech
  Email:bluecitynetwork@outlook.com
  License:GPL V3.0
  Rev 3.0a
*/
// defines
#include <MUIU8g2.h>
#include <U8x8lib.h>
#define SUN 0
#define SUN_CLOUD 1
#define CLOUD 2
#define RAIN 3
#define THUNDER 4
#define SNOW 5
#define MIST 6 //雾
#define MOON 7

// includes
#include <EEPROM.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include <ArduinoOTA.h>
#include <WiFiClientSecure.h>
#include <ESP8266mDNS.h>
#include <TimeLib.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266HTTPUpdateServer.h>
#include <U8g2lib.h>
#include <coredecls.h>
#include <Arduino.h>
#include <include/WiFiState.h>
#include <LittleFS.h>
#include "pitches.h" // LittleFS is declared
short melody[] = {
  NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_A4, NOTE_E4, NOTE_G4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_A3, NOTE_C4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_A4, NOTE_E4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_A3, NOTE_G3, NOTE_D4, NOTE_C4, NOTE_E4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_A4, NOTE_E4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_A3, NOTE_G3, NOTE_C4, NOTE_C4, 0, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_G4, NOTE_G4, NOTE_G4, NOTE_E3, NOTE_G4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_G3, NOTE_A3, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_D4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_A4, NOTE_C5, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_A4, NOTE_E4, NOTE_D4, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_C4, NOTE_A3, NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_G4, NOTE_G4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_A4, NOTE_C5, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_G3, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_A4, NOTE_D5, NOTE_C5, NOTE_G4, NOTE_C5, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_C4, NOTE_A3, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_A3, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_G4, NOTE_A4, NOTE_E4, NOTE_G4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_C5, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_G3, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_C4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_A4, NOTE_C5, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_G3, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_C4, NOTE_D4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_C5, NOTE_A4, NOTE_C5, NOTE_A3, NOTE_A3, NOTE_C4, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_D4, NOTE_E4, NOTE_A3, NOTE_A3, NOTE_C4, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_D4, NOTE_A3, NOTE_A3, NOTE_C4, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_C4, NOTE_D4, NOTE_A4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_A4, NOTE_A3, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_C4, 0, 0, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_A4, 0, 0, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_D4, NOTE_E4, NOTE_A3, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_C4, 0, 0, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_A4, 0, 0, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_A4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_G4, NOTE_A4
};

//定义音长，8表示8分音符
byte noteDurations[] = {
  8, 16, 16, 8, 8, 2, 8, 16, 16, 8, 8, 2, 8, 16, 16, 8, 8, 8, 8, 8, 8, 16 / 3, 16, 8, 8, 2, 8, 16, 16, 8, 8, 2, 8, 16, 16, 8, 8, 2, 8, 8, 8, 8, 8, 8, 8, 8, 16 / 3, 16, 8, 8, 2, 8, 16, 16, 8, 8, 8 / 3, 8, 8, 16, 16, 8, 8, 2, 8, 16, 16, 8, 8, 8, 8, 8, 8, 8 / 3, 8, 2, 8, 16, 16, 8, 8, 8 / 3, 8, 8, 16, 16, 8, 8, 2, 8, 16, 16, 8, 8, 8, 8, 8, 8, 8 / 3, 8 / 3, 4, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 4, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 4, 8, 16, 16, 8, 8, 16, 16, 16, 16, 8, 16, 16, 8, 16, 16, 16, 16, 16, 16, 8, 16, 16, 4, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 4, 8, 16, 16, 8, 8, 16, 16, 16, 16, 4, 8, 16, 16, 8, 8, 16, 16, 16, 16, 8, 16, 16, 16, 16, 16, 16, 8, 8, 8, 8, 4, 32 / 3, 32, 16, 16, 16, 16, 8, 8, 8, 4, 8, 16, 16, 8, 16, 16, 16, 16, 16, 16, 4, 8, 16, 16, 8, 8, 16, 16, 16, 16, 4, 8, 16, 16, 8, 8, 16, 16, 16, 16, 8, 16, 16, 8, 16, 16, 8, 16, 16, 8, 8, 16, 16, 16, 16, 4, 8, 16, 16, 8, 8, 16, 16, 16, 16, 8, 16, 16, 8, 16, 16, 8, 8, 16, 16, 16, 16, 4, 16, 16, 16, 16, 8, 16, 16, 8, 8, 4, 8, 16, 16, 8, 8, 8, 8, 8, 8, 8, 16, 16, 8, 8, 2, 8, 16, 16, 8, 8, 8, 8, 8, 8, 8, 16, 16, 8, 8, 2, 8, 16, 16, 8, 8, 8, 8, 8, 8, 8, 16, 16, 8, 8, 8 / 3, 16, 16, 8 / 3, 8, 4, 4, 1 / 2, 8, 16, 16, 8, 8, 4, 4, 8, 16, 16, 8, 8, 4, 4, 16 / 3, 16, 8, 8, 4, 4, 1 / 2, 8, 16, 16, 8, 8, 4, 4, 8, 16, 16, 8, 8, 4, 4, 16 / 3, 16, 8, 8, 4, 4, 1 / 2, 16 / 3, 16, 8, 8, 8, 4, 8, 1 / 2
};

int itoneLen;
// includes end

// vars start
bool wea = false, cw[7], offline;
String file_name = "/sysconfig";
static const char ntpServerName[] = "ntp1.aliyun.com"; // NTP服务器，阿里云
int timeZone = 8;                                      //时区，北京时间为+8
String ver = "V3", hitok = "yeah!", deviceOwner = "Yan";

unsigned int localPort = 8888; // 用于侦听UDP数据包的本地端口
bool powersave = false, ismuted = false;
boolean isNTPConnected = false, clk = true;
int scrLightTime = 10;
//DYWiFiConfig wificonfig;
WiFiClient client;
WiFiUDP Udp;
FSInfo fs_info;
File dataFile;
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /*reset=*/U8X8_PIN_NONE);
ESP8266WebServer webserver(80);
ESP8266HTTPUpdateServer httpUpdater;
// vars end

// funcs start
time_t getNtpTime();
void sendNTPpacket(IPAddress& address);
void oledClockDisplay();
void sendCommand(int command, int value);
void initdisplay();
// funcs end

void beep(int hz, int tm)
{
	if (!ismuted)
		tone(D8, hz, tm);
}
void HLDDZ()
{
	itoneLen = sizeof(melody) / sizeof(melody[0]);
	for (int thisNote = 0; thisNote < itoneLen; thisNote++) {
		int noteDuration = 1.5 * 1000 / noteDurations[thisNote]; // 全音符音长1.5*1000ms，四分音符则除以4

		tone(D8, melody[thisNote], noteDuration);  //使用8号引脚

		int pauseBetweenNotes = noteDuration * 1.30;   //响完一个音后的停顿时间
		delay(pauseBetweenNotes);
		noTone(D8);
	}
}
void setup()
{
	timeZone = 8;
	pinMode(D7, INPUT_PULLUP);
	pinMode(D5, OUTPUT);
	Serial.begin(115200);
	u8g2.begin(D5, D7, D6);
	u8g2.enableUTF8Print();
	u8g2.setFontMode(0);
	u8g2.clearBuffer();
	u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
	u8g2.sendBuffer();
	Serial.print(F("\nReset reason = ") + ESP.getResetReason());
	beep(262, 100);
	delay(100);
	beep(352, 100);
	delay(100);
	beep(452, 100);
	delay(100);
	u8g2.setCursor(0, 14);
	u8g2.print(F("Reason:") + ESP.getResetReason());
	u8g2.sendBuffer();
	u8g2.setCursor(0, 30);

	if (LittleFS.begin())
	{ // 启动闪存文件系统
		Serial.println(F("LittleFS Started."));
		u8g2.print(F("LittleFS Started."));
		delay(500);
	}
	else
	{
		Serial.println(F("LittleFS Failed to Start."));
		u8g2.print(F("[!]LittleFS Error!"));
		beep(262, 500);
		delay(3000);
	}
	u8g2.sendBuffer();
	u8g2.setCursor(0, 47);

	if (LittleFS.exists(file_name))
	{
		Serial.print(file_name);
		Serial.println(F(" FOUND."));
		u8g2.print(F("Found SysConfig."));
	}
	else
	{
		Serial.print(file_name);
		Serial.print(F(" NOT FOUND."));
		u8g2.print(F("SysConfig Lost."));
		beep(262, 500);
		delay(500);
		File dFile = LittleFS.open(file_name, "w");
		dFile.close(); // 完成文件写入后关闭文件
		Serial.println(F("Finished Writing data to LittleFS"));
	}
	u8g2.sendBuffer();
	delay(1000);

	// u8g2.setFont(u8g2_font_unifont_dx);
	u8g2.clearBuffer();
	u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
	u8g2.setCursor(0, 14);
	u8g2.print(F("正在搜索网络"));
	u8g2.setCursor(0, 30);
	u8g2.print(F("使用手机配网或按OK键"));
	u8g2.setCursor(0, 47);
	u8g2.print(F("CokeeTech ") + ver);
	u8g2.setCursor(0, 64);
	u8g2.print(F("SWDate:2022/12/24."));
	u8g2.sendBuffer();

	int j = 0;
	WiFi.begin(F("Xiaomi_DFCB"), F(":123456789"));
	//WiFi.begin(F("CokeeNetworks"), F("666688881234"));
	while (WiFi.status() != WL_CONNECTED)
	{
		Serial.print("BTN|STA:");
		Serial.print(digitalRead(D5));
		Serial.println(WiFi.status());
		if (u8g2.getMenuEvent() == U8X8_MSG_GPIO_MENU_SELECT)
		{
			scanWF();
		}
		if (WiFi.status() == WL_NO_SSID_AVAIL || WiFi.status() == WL_CONNECT_FAILED)
		{
			// Wifiinfo();
			Serial.print("FAIL");
			scanWF();
		}
		delay(500);
	}

	u8g2.clearBuffer();

	u8g2.setCursor(0, 14);
	u8g2.print(F("网络已连接 >v<"));
	u8g2.setCursor(0, 30);
	u8g2.print(F("3 秒后进入主界面"));
	u8g2.setCursor(0, 47);
	u8g2.print(WiFi.SSID());
	u8g2.setCursor(0, 64);
	u8g2.print(F("IP:") + WiFi.localIP().toString());
	u8g2.sendBuffer();

	delay(3000);
	Serial.print(F("timeZone:"));
	Serial.print(timeZone);
	Serial.println(WiFi.localIP());
	Udp.begin(localPort);
	setSyncProvider(getNtpTime);
	setSyncInterval(30); //每300秒同步一次时间
	isNTPConnected = true;
	webserver.on("/sw", []()
		{
			if (wea)
				wea = false;
			else
				wea = true;
			webserver.send(200, F("text/plain"), F("switch weather ok"));
		});
	httpUpdater.setup(&webserver, "/update", "cokee", "cokeetech@233");
	webserver.begin();
	Serial.println(F("Ready"));
	Serial.print(F("IP address:"));
	Serial.println(WiFi.localIP());
	// attachInterrupt(D6,bn,FALLING);
	// sersons.begin();
	// wificonfig.begin(&webserver, "/", "Cokee MicroDP");
	u8g2.updateDisplay();
}

time_t prevDisplay = 0; //当时钟已经显示
void loop()
{
	if (u8g2.getMenuEvent() == U8X8_MSG_GPIO_MENU_SELECT && !wea)
	{
		if (powersave)
		{
			powersave = false;
			u8g2.setPowerSave(0);
			return;
		}
		if (wea)
			return;
		else
			btn_event();
	}
	if (timeStatus() != timeNotSet && !wea)
	{
		if (second() != prevDisplay)
		{ //时间改变时更新显示
			prevDisplay = second();
			oledClockDisplay();
			checkAlarm();
		}
	}
	if (!powersave)
	{
		webserver.handleClient();
		ArduinoOTA.handle();
		// MDNS.update();
	}
	// wificonfig.handle();
}
void checkAlarm()
{
	//if(hour()==)
}
/*
void changeLang()
{
	dataFile = LittleFS.open(file_name, "r+");
	dataFile.seek(1, SeekCur);
	u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
	int c1 = u8g2.userInterfaceSelectionList("Language/语言", c1, langlist);
	if (c1 == 1)
	{
		lang = "zh_cn";
		dataFile.write(1);
	}
	if (c1 == 2)
	{
		lang = "en_us";
		dataFile.write(2);
	}
	dataFile.close();
}*/
void btn_event()
{
	beep(262, 100);
	// u8g2.setFont(u8g2_font_6x12_tr);
	u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
	uint8_t current_selection = 0, c1 = 0;

	const char* string_list =
		"天气\n"            // 1
		"WiFi信息\n"        // 2
		"WiFi列表\n"        // 3
		"WiFi配置\n"        // 4
		"闹钟\n"				// 5
		"休眠模式\n"         // 6
		"时区设置\n"         // 7
		"屏幕设置\n"        // 8
		"声音设置\n"        // 9
		"检查固件更新\n"    // 10
		"设备信息\n"        // 11
		"恢复出厂设置"; // 12
	const char* s9 =
		(F("亮屏时间:") + String(scrLightTime) + "秒\n").c_str();
	"旋转:0 度-正常\n"
		"旋转:180 度";
	const char* tzl =
		"UTC+\n"
		"UTC-";
	current_selection = u8g2.userInterfaceSelectionList("主菜单", current_selection, string_list);
	if (current_selection == 0)
		u8g2.userInterfaceMessage("Nothing selected. >_<", "", "", " ok ");
	else
	{
		switch (current_selection)
		{
		case 1:
			weather();
			break;
		case 2:
			alarm();
			break;
		case 4:
			Wifiinfo();
			break;
		case 5:
			scanWF();
			break;
		case 6:
			WiFi.disconnect();
			break;
		case 7:
			uint8_t tz;
			current_selection = u8g2.userInterfaceSelectionList("选择/Choose", current_selection, tzl);
			if (current_selection == 1)
			{
				u8g2.userInterfaceInputValue("时区(世界协调时差)", "UTC+", &tz, 0, 12, 2, " 小时");

				timeZone = tz;
			}
			else if (current_selection == 2)
			{
				u8g2.userInterfaceInputValue("时区(世界协调时差)", "UTC-", &tz, 0, 12, 2, " 小时");

				timeZone = 0 - tz;
			}

			break;
		case 8:
			c1 = u8g2.userInterfaceSelectionList("屏幕旋转", c1, s9);
			if (c1 == 2)
			{
				uint8_t to;
				u8g2.userInterfaceInputValue("亮屏时间 ScrTimeout", "", &to, 3, 15, 2, " 秒/sec");
				scrLightTime = to;
			}
			if (c1 == 2)
				u8g2.setDisplayRotation(U8G2_R0);
			if (c1 == 3)
				u8g2.setDisplayRotation(U8G2_R2);
			break;
		case 9:
			powersave = true;
			u8g2.setPowerSave(1);
			//WiFi.shutdown(nv->wss);
			ESP.deepSleep(1000, RF_DISABLED);
			break;
		case 12:

		case 13:
			FSInfo fs_info;
			LittleFS.info(fs_info);
			u8g2.userInterfaceMessage(String(F("设备ID:") + String(ESP.getChipId())).c_str(), "Cokee Tech.", "代号:循星 v5", " ok ");
			// u8g2.userInterfaceMessage("Flash空间:" + fs_info.totalBytes /*+"bytes"*/, "已用空间:" + fs_info.usedBytes, "软件版本:", " ok ");
			u8g2.userInterfaceMessage(("设备所属人:" + deviceOwner).c_str(), "Made with Heart", "(●'◡'●)", " ok ");
			break;
		case 14:
			hitoko();
			// draw_state_scroll1();
			break;
		case 15:
			hitoko();
			// draw_state_scroll1();
			break;
		default:
			u8g2.userInterfaceMessage(
				"Selection:",
				u8x8_GetStringLineStart(current_selection - 1, string_list),
				" >_<",
				" ok \n cancel ");
			HLDDZ();
			u8g2.updateDisplay();
			break;
		}
	}
	// scanWF();
}
void Wifiinfo()
{
	String wfs;
	switch (WiFi.status())
	{
	case 0:
		wfs = String(F("Changing 变换中"));
		break;
	case 1:
		wfs = String(F("NO_SSID 无网络"));
		break;
	case 3:
		wfs = String(F("CONNECTED 已连接"));
		break;
	case 4:
		wfs = String(F("CN_FAIL 连接失败"));
		break;
	case 6:
		wfs = String(F("WRONG_PW 密码错误"));
		break;
	case 7:
		wfs = String(F("DISCONNECTED断开"));
		break;
	}

	u8g2.userInterfaceMessage(
		wfs.c_str(),
		String(WiFi.SSID()).c_str(),
		String(WiFi.RSSI()).c_str(),
		" ok ");
	u8g2.updateDisplay();
} /*
  int SelectionList(String title,int num,const char* list)
  {
   int current_pos=0;
   //title start
   for(;;)
   {
	 u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
	 int y=1;//调节位移速度，可用于加快字符位移速度
	 for(int x=0;x<256;x+=y)//x+=y ----->等价于x=x+y
	 {
	   u8g2.clearBuffer();         // 清除内部缓冲
	   u8g2.drawStr(x,10,"Hello World!");  // 第一段输出位置
	   u8g2.drawStr(x-128,10,"Hello World!");//第二段输出位置
	   delay(20);//延时程序，可以降低位移速度
	   u8g2.sendBuffer();          // transfer internal memory to the displa
	 }

   //title end
	 for(;;)
	   {
		 int event=0;
		 event = u8x8_GetMenuEvent();
		 if ( event == U8X8_MSG_GPIO_MENU_SELECT )
		   return current_pos+1;
		 else if ( event == U8X8_MSG_GPIO_MENU_HOME )
		   return 0;
		 else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_DOWN )
		 {
		   //u8sl_Next(&u8sl);
		   break;
		 }
		 else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_UP )
		 {
		  // u8sl_Prev(&u8sl);
		   break;
		 }
	   }
   }
  }*/
void alarm()
{
	uint8_t current_selection = 0;
	const char* string_list =
		"[New 新闹钟]\n"
		"[Exit 退出]";
	/*for()
	  {
	  }*/

	current_selection = u8g2.userInterfaceSelectionList(
		"Alarm List",
		current_selection,
		string_list);
	if (current_selection == 0)
	{
		u8g2.userInterfaceMessage(
			"Nothing selected.",
			"",
			"",
			" ok ");
	}
	else
	{
		switch (current_selection)
		{
		case 1:

			break;
		case 3:
			alarm();
			break;

		default:
			u8g2.userInterfaceMessage(
				"Selection:",
				u8x8_GetStringLineStart(-1, string_list),
				"",
				" ok \n cancel ");
			break;
		}
	}
	u8g2.updateDisplay();
}
int wid = 17;
void oledClockDisplay()
{
	if (wea)
		return;
	int years, months, days, hours, minutes, seconds, weekdays;
	years = year();
	months = month();
	days = day();
	hours = hour();
	minutes = minute();
	seconds = second();
	weekdays = weekday();
	// Serial.printf(F("%d/%d/%d%d:%d:%d Weekday:%d\n",years,months,days,hours,minutes,seconds,weekdays);
	u8g2.clearBuffer();
	u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
	u8g2.setCursor(0, 14);
	u8g2.print(F("内部版本"));
	draw_State();
	/*if(wid>=u8g2.getDisplayWidth())wid=17;
	  draw_state_scroll1(wid,14);*/
	u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
	String currentTime = "";
	if (hours < 10)
		currentTime += 0;
	currentTime += hours;
	currentTime += ":";
	if (minutes < 10)
		currentTime += 0;
	currentTime += minutes;
	currentTime += ":";
	if (seconds < 10)
		currentTime += 0;
	currentTime += seconds;
	String currentDay = "";
	currentDay += years;
	currentDay += "/";
	if (months < 10)
		currentDay += 0;
	currentDay += months;
	currentDay += "/";
	if (days < 10)
		currentDay += 0;
	currentDay += days;
	u8g2.setFont(u8g2_font_logisoso24_tr);
	u8g2.setCursor(0, 44);
	u8g2.print(currentTime);
	u8g2.setCursor(0, 59);
	u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
	u8g2.print(currentDay);
	u8g2.setCursor(90, 62);

	u8g2.print(F("星期"));
	if (weekdays == 1)
		u8g2.print(F("日"));
	else if (weekdays == 2)
		u8g2.print(F("一"));
	else if (weekdays == 3)
		u8g2.print(F("二"));
	else if (weekdays == 4)
		u8g2.print(F("三"));
	else if (weekdays == 5)
		u8g2.print(F("四"));
	else if (weekdays == 6)
		u8g2.print(F("五"));
	else if (weekdays == 7)
		u8g2.print(F("六"));

	//wid++;
	u8g2.sendBuffer();
}

/*--------NTP 代码----------*/

const int NTP_PACKET_SIZE = 48;     // NTP时间在消息的前48个字节里
byte packetBuffer[NTP_PACKET_SIZE]; // 输入输出包的缓冲区

time_t getNtpTime()
{
	IPAddress ntpServerIP; // NTP服务器的地址

	while (Udp.parsePacket() > 0)
		; // 丢弃以前接收的任何数据包
	  // 从池中获取随机服务器
	WiFi.hostByName(ntpServerName, ntpServerIP);
	Serial.print(ntpServerName);
	Serial.print(F(":"));
	Serial.println(ntpServerIP);
	sendNTPpacket(ntpServerIP);
	uint32_t beginWait = millis();
	while (millis() - beginWait < 1500)
	{
		int size = Udp.parsePacket();
		if (size >= NTP_PACKET_SIZE)
		{
			Serial.println(F("Receive NTP Response"));
			isNTPConnected = true;
			Udp.read(packetBuffer, NTP_PACKET_SIZE); // 将数据包读取到缓冲区
			unsigned long secsSince1900;
			// 将从位置40开始的四个字节转换为长整型，只取前32位整数部分
			secsSince1900 = (unsigned long)packetBuffer[40] << 24;
			secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
			secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
			secsSince1900 |= (unsigned long)packetBuffer[43];
			Serial.println(secsSince1900);
			Serial.println(secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR);
			return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
		}
	}
	Serial.println(F("No NTP Response:-(")); //无NTP响应
	isNTPConnected = false;
	return 0; //如果未得到时间则返回0
}

// 向给定地址的时间服务器发送NTP请求
void sendNTPpacket(IPAddress& address)
{
	memset(packetBuffer, 0, NTP_PACKET_SIZE);
	packetBuffer[0] = 0b11100011; // LI,Version,Mode
	packetBuffer[1] = 0;          // Stratum,or type of clock
	packetBuffer[2] = 6;          // Polling Interval
	packetBuffer[3] = 0xEC;       // Peer Clock Precision
	// 8 bytes of zero for Root Delay&Root Dispersion
	packetBuffer[12] = 49;
	packetBuffer[13] = 0x4E;
	packetBuffer[14] = 49;
	packetBuffer[15] = 52;
	Udp.beginPacket(address, 123); // NTP需要使用的UDP端口号为123
	Udp.write(packetBuffer, NTP_PACKET_SIZE);
	Udp.endPacket();
}

void scanWF()
{
	int i, n;
	String menu;
	uint8_t current_selection = 1;
	u8g2.setFont(u8g2_font_wqy13_t_chinese2);
	wea = true;
	//  wificonfig.enableAP();
	WiFi.scanNetworks(true);
	while (WiFi.scanComplete() >= 0)
	{
		int n = WiFi.scanComplete();
		if (n == 0)
		{
			u8g2.userInterfaceMessage(
				"错误",
				"找不到可用的网络",
				"",
				" ok ");
			goto ex;
		}
		u8g2.clearBuffer();
		for (i = 0; i < n; i++)
		{
			if (WiFi.encryptionType(i) == ENC_TYPE_NONE)
				menu += "<O>";
			if (i < n)
				menu += String(WiFi.SSID(i)) + "\n";
			else
				menu += String(WiFi.SSID(i));
		}
		menu += "\n[Exit 退出]";
		current_selection = u8g2.userInterfaceSelectionList(
			"WIFI List",
			current_selection,
			menu.c_str());

		if (current_selection == 0)
		{
			u8g2.userInterfaceMessage(
				"Nothing selected.",
				"",
				"",
				" OK ");
			goto ex;
		}
		else
		{
			const char* sd = u8x8_GetStringLineStart(current_selection - 1, menu.c_str());
			Serial.println(sd);
			if (current_selection == WiFi.scanComplete())
			{
				offline = true;
				goto ex;
			}
			if (WiFi.encryptionType(current_selection - 1) != ENC_TYPE_NONE)
			{
				uint8_t inp;
				u8g2.userInterfaceInputValue("Password", "PW:", &inp, 0, 5, 1, " |");
				/*u8g2.userInterfaceMessage(
					"Password:",
					inp.c_str(),
					"",
					" Connect ");*/
				Serial.println(inp);
				u8g2.clearBuffer();
				u8g2.print(F("Try to connect"));
				u8g2.sendBuffer();
				// WiFi.begin(WiFi.SSID(current_selection - 1), );
				unsigned long c = millis();

				while (WiFi.status() != WL_CONNECTED)
				{
					delay(100);
					u8g2.print(F("."));
					u8g2.sendBuffer();
					if (millis() - c >= 10000)
					{
						wea = false;
						c = 0;
						return;
					}
				}
				wea = false;
				return;
				c = 0;
				/*u8g2.clearBuffer();u8g2.setCursor(0,14);
						  u8g2.print(F(F("Wifi isn't open!"));u8g2.sendBuffer();delay(3000);*/
			}
			else
			{
				//if (WiFi.SSID(current_selection - 1) != DEF_WIFI_SSID)
				//	WiFi.begin(WiFi.SSID(current_selection - 1), "");
				WiFi.begin(WiFi.SSID(current_selection - 1), "");
				u8g2.clearBuffer();
				u8g2.setCursor(0, 14);
				u8g2.print(F("Try to connect"));
				u8g2.setCursor(0, 28);
				u8g2.sendBuffer();
				unsigned long c = millis();
				while (WiFi.status() != WL_CONNECTED)
				{
					delay(100);
					u8g2.print(F("."));
					u8g2.sendBuffer();
					if (millis() - c >= 10000)
					{
						wea = false;
						c = 0;
						return;
					}
				}
				wea = false;
				c = 0;
				return;
			}
		}
		delay(10);
	}

ex:
	wea = false;
	return;
}
void draw_State()
{
	u8g2.setFont(u8g2_font_open_iconic_www_1x_t);
	if (WiFi.status() == WL_CONNECTED)
	{
		u8g2.drawGlyph(0, 8, 72);
	}
	else if (WiFi.status() == WL_DISCONNECTED)
	{
		if ((millis() % 1000) > 500)
			u8g2.drawGlyph(0, 8, 69);
	}
	else if (WiFi.status() == WL_NO_SSID_AVAIL)
	{
		if ((millis() % 1000) > 500)
			u8g2.drawGlyph(0, 8, 79);
	}
	else if (WiFi.status() == WL_IDLE_STATUS)
	{
		if ((millis() % 1000) > 500)
			u8g2.drawGlyph(0, 8, 81);
	}

	// show weather state
}
int C_F;
int16_t OFFSET = -(int16_t)u8g2.getDisplayWidth();
;
void drawScrollString1(int x_offset, int16_t offset, const char* s)
{
	static char buf[36]; // should for screen with up to 256 pixel width
	size_t len;
	size_t char_offset = 0;
	u8g2_uint_t dx = 0;
	size_t visible = 0;
	len = strlen(s);
	if (offset < 0)
	{
		char_offset = (-offset) / 6;
		dx = offset + char_offset * 6;
		if (char_offset >= u8g2.getDisplayWidth() / 6)
			return;
		visible = u8g2.getDisplayWidth() / 6 - char_offset + 1;
		strncpy(buf, s, visible);
		buf[visible] = '\0';
		// u8g2.setFont(u8g2_font_6x10_mf);
		u8g2.setFont(u8g2_font_wqy12_t_chinese2);
		u8g2.drawStr(char_offset * 6 - dx + x_offset, 7, buf);
	}
	else
	{
		char_offset = offset / 6;
		if (char_offset >= len)
			return; // nothing visible
		dx = offset - char_offset * 6;
		visible = len - char_offset;
		if (visible > u8g2.getDisplayWidth() / 6 + 1)
			visible = u8g2.getDisplayWidth() / 6 + 1;
		strncpy(buf, s + char_offset, visible);
		buf[visible] = '\0';
		// u8g2.setFont(u8g2_font_6x10_mf);
		u8g2.setFont(u8g2_font_wqy12_t_chinese2);
		u8g2.drawStr(-dx + x_offset, 7, buf);
	}
}

void draw_state_scroll1(int tx, int ty)
{
	u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
	// for(int x=0;x<256;x+=1)
	// x+=y ----->等价于x=x+y
	// u8g2.clearBuffer();         // 清除内部缓冲区
	u8g2.drawStr(tx, ty, "Hello World!");       // 第一段输出位置
	//u8g2.drawStr(tx - 128, 10, "Hello World!"); //第二段输出位置
	// delay(20);//延时程序，可以降低位移速度
	u8g2.sendBuffer(); // transfer internal memory to the displa
}

void weather()
{
	WiFiClient aclient;
	String json_from_server, city = "Fuyang";
	String url = "http://api.seniverse.com/v3/weather/daily.json?key=SISi82MwzaMbmQqSh&location=fuyang&language=zh-Hans&unit=c&start=0&days=3";
	HTTPClient http;

	Serial.print(F("[HTTP] begin...\n"));
	if (http.begin(aclient, url.c_str()))
	{ // HTTP
		Serial.print(F("[HTTP] GET...\n"));
		// start connection and send HTTP header
		int httpCode = http.GET();

		// httpCode will be negative on error
		if (httpCode > 0)
		{
			// HTTP header has been send and Server response header has been handled
			Serial.printf("[HTTP] GET... code:%d\n", httpCode);

			// file found at server
			if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY)
			{
				json_from_server = http.getString();
				Serial.println(json_from_server);
			}
		}
		else
		{
			Serial.printf("[HTTP] GET... failed,error:%s\n", http.errorToString(httpCode).c_str());
		}

		http.end();
	}
	else
	{
		Serial.printf("[HTTP} Unable to connect\n");
		return;
	}

	const size_t capacity = JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(6) + 3 * JSON_OBJECT_SIZE(14) + 800;
	DynamicJsonDocument doc(capacity);
	deserializeJson(doc, json_from_server.c_str());

	JsonObject results_0 = doc["results"][0];
	JsonObject results_0_location = results_0["location"];
	const char* results_0_location_name = results_0_location["name"];                       // "阜阳"
	const char* results_0_location_country = results_0_location["country"];                 // "CN"
	const char* results_0_location_path = results_0_location["path"];                       // "阜阳,阜阳,安徽,中国"
	const char* results_0_location_timezone = results_0_location["timezone"];               // "Asia/Shanghai"
	const char* results_0_location_timezone_offset = results_0_location["timezone_offset"]; // "+08:00"

	JsonArray results_0_daily = results_0["daily"];

	JsonObject results_0_daily_0 = results_0_daily[0];
	const char* results_0_daily_0_date = results_0_daily_0["date"];             // "2020-04-04"
	const char* results_0_daily_0_text_day = results_0_daily_0["text_day"];     // "多云"
	const char* results_0_daily_0_code_day = results_0_daily_0["code_day"];     // "4"
	const char* results_0_daily_0_text_night = results_0_daily_0["text_night"]; // "多云"
	const char* results_0_daily_0_code_night = results_0_daily_0["code_night"]; // "4"
	const char* results_0_daily_0_high = results_0_daily_0["high"];             // "21"
	const char* results_0_daily_0_low = results_0_daily_0["low"];               // "6"
	const char* results_0_daily_0_rainfall = results_0_daily_0["rainfall"];     // "0.0"
	const char* results_0_daily_0_humidity = results_0_daily_0["humidity"];     // "62"

	JsonObject results_0_daily_1 = results_0_daily[1];
	const char* results_0_daily_1_date = results_0_daily_1["date"];             // "2020-04-05"
	const char* results_0_daily_1_text_day = results_0_daily_1["text_day"];     // "多云"
	const char* results_0_daily_1_code_day = results_0_daily_1["code_day"];     // "4"
	const char* results_0_daily_1_text_night = results_0_daily_1["text_night"]; // "阴"
	const char* results_0_daily_1_code_night = results_0_daily_1["code_night"]; // "9"
	const char* results_0_daily_1_high = results_0_daily_1["high"];             // "17"
	const char* results_0_daily_1_low = results_0_daily_1["low"];               // "7"
	const char* results_0_daily_1_rainfall = results_0_daily_1["rainfall"];     // "0.0"
	const char* results_0_daily_1_humidity = results_0_daily_1["humidity"];     // "47"

	JsonObject results_0_daily_2 = results_0_daily[2];
	const char* results_0_daily_2_date = results_0_daily_2["date"];             // "2020-04-06"
	const char* results_0_daily_2_text_day = results_0_daily_2["text_day"];     // "晴"
	const char* results_0_daily_2_code_day = results_0_daily_2["code_day"];     // "0"
	const char* results_0_daily_2_text_night = results_0_daily_2["text_night"]; // "多云"
	const char* results_0_daily_2_code_night = results_0_daily_2["code_night"]; // "4"
	const char* results_0_daily_2_high = results_0_daily_2["high"];             // "19"
	const char* results_0_daily_2_low = results_0_daily_2["low"];               // "8"
	const char* results_0_daily_2_rainfall = results_0_daily_2["rainfall"];     // "0.0"
	const char* results_0_daily_2_humidity = results_0_daily_2["humidity"];     // "48"

	const char* results_0_last_update = results_0["last_update"]; // "2020-04-04T17:25:51+08:00"

	int wtemp[3] = { (atoi(results_0_daily_0_high) + atoi(results_0_daily_0_low)) / 2, (atoi(results_0_daily_1_high) + atoi(results_0_daily_1_low)) / 2, (atoi(results_0_daily_2_high) + atoi(results_0_daily_2_low)) / 2 };
	int tdst[3] = { atoi(results_0_daily_0_code_day), atoi(results_0_daily_1_code_day), atoi(results_0_daily_2_code_day) };
	String wtext[3] = { city + " today's weather:" + String(results_0_daily_0_text_day), city + " tomorrow's weather:" + String(results_0_daily_1_text_day), city + " day after tomorrow's weather:" + String(results_0_daily_2_text_day) };

	Serial.println();
	Serial.println(wtext[0]);
	Serial.println(wtext[1]);
	Serial.println(wtext[2]);
	draw(wtext[0].c_str(), pdweather(tdst[0]), wtemp[0]);
	// Wait 5 seconds
	delay(2000);
	draw(wtext[1].c_str(), pdweather(tdst[1]), wtemp[1]);
	delay(2000);
	draw(wtext[2].c_str(), pdweather(tdst[2]), wtemp[2]);
	delay(5000);
	wea = false;
}
int pdweather(int ctd)
{
	int tds = 0;
	if (ctd == 0 || ctd == 3 || ctd == 38)
	{
		tds = SUN;
	}
	else if (ctd == 1 || ctd == 2 || ctd == 38)
	{
		tds = MOON;
	}
	else if (ctd >= 4 && ctd <= 8)
	{
		tds = SUN_CLOUD;
	}
	else if (ctd >= 10 && ctd <= 25)
	{
		tds = RAIN;
	}
	else if (ctd == 9)
	{
		tds = CLOUD;
	}
	else if (ctd == 30 || ctd == 31)
	{
		tds = MIST;
	}
	return tds;
}
void drawWeatherSymbol(u8g2_uint_t x, u8g2_uint_t y, uint8_t symbol)
{
	// fonts used:
	// u8g2_font_open_iconic_embedded_6x_t
	// u8g2_font_open_iconic_weather_6x_t
	// encoding values,see:https://github.com/olikraus/u8g2/wiki/fntgrpiconic

	switch (symbol)

	{
	case SUN:

		u8g2.setFont(u8g2_font_open_iconic_weather_6x_t);

		u8g2.drawGlyph(x, y, 69);

		break;

	case SUN_CLOUD:

		u8g2.setFont(u8g2_font_open_iconic_weather_6x_t);

		u8g2.drawGlyph(x, y, 65);

		break;

	case CLOUD:

		u8g2.setFont(u8g2_font_open_iconic_weather_6x_t);

		u8g2.drawGlyph(x, y, 64);

		break;

	case RAIN:

		u8g2.setFont(u8g2_font_open_iconic_weather_6x_t);

		u8g2.drawGlyph(x, y, 67);

		break;

	case THUNDER: //雷

		u8g2.setFont(u8g2_font_open_iconic_embedded_6x_t);

		u8g2.drawGlyph(x, y, 67);

		break;

	case SNOW: //雪

		u8g2.setFont(u8g2_font_open_iconic_weather_6x_t);

		u8g2.drawGlyph(x, y, 68);

		break;

	case MIST: //雾

		u8g2.setFont(u8g2_font_open_iconic_text_6x_t);

		u8g2.drawGlyph(x, y, 64);

		break;

	case MOON:

		u8g2.setFont(u8g2_font_open_iconic_weather_6x_t);

		u8g2.drawGlyph(x, y, 66);

		break;
	}
}

void drawWeather(uint8_t symbol, int degree)
{
	drawWeatherSymbol(0, 48, symbol);
	u8g2.setFont(u8g2_font_logisoso32_tf);
	u8g2.setCursor(48 + 3, 42);
	u8g2.print(degree);
	u8g2.print(F("°C")); // requires enableUTF8Print()
}
/*
  Draw a string with specified pixel offset.
  The offset can be negative.
  Limitation:The monochrome font with 8 pixel per glyph
*/
void drawScrollString(int16_t offset, const char* s)
{
	static char buf[36]; // should for screen with up to 256 pixel width
	size_t len;
	size_t char_offset = 0;
	u8g2_uint_t dx = 0;
	size_t visible = 0;
	len = strlen(s);
	if (offset < 0)
	{
		char_offset = (-offset) / 8;
		dx = offset + char_offset * 8;
		if (char_offset >= u8g2.getDisplayWidth() / 8)
			return;
		visible = u8g2.getDisplayWidth() / 8 - char_offset + 1;
		strncpy(buf, s, visible);
		buf[visible] = '\0';
		// u8g2.setFont(u8g2_font_8x13_mf);
		u8g2.enableUTF8Print();
		u8g2.setFont(u8g2_font_wqy13_t_gb2312a);
		u8g2.drawUTF8(char_offset * 8 - dx, 62, buf);
	}
	else
	{
		char_offset = offset / 8;
		if (char_offset >= len)
			return; // nothing visible
		dx = offset - char_offset * 8;
		visible = len - char_offset;
		if (visible > u8g2.getDisplayWidth() / 8 + 1)
			visible = u8g2.getDisplayWidth() / 8 + 1;
		strncpy(buf, s + char_offset, visible);
		buf[visible] = '\0';
		// u8g2.setFont(u8g2_font_8x13_mf);
		u8g2.enableUTF8Print();
		u8g2.setFont(u8g2_font_wqy13_t_gb2312a);

		u8g2.drawUTF8(-dx, 62, buf);
	}
}

void draw(const char* s, uint8_t symbol, int degree)
{
	int16_t offset = -(int16_t)u8g2.getDisplayWidth();
	int16_t len = strlen(s);
	for (;;)
	{
		u8g2.firstPage();
		do
		{
			drawWeather(symbol, degree);
			drawScrollString(offset, s);
		} while (u8g2.nextPage());
		delay(20);
		offset += 2;
		if (offset > len * 8 + 1)
			break;
	}
}
void hitoko()
{
	// http://api.guaqb.cn/v1/onesaid/
	HTTPClient Client1;
	String url = "http://api.guaqb.cn/v1/onesaid/";
	String httpString;
	if (Client1.begin(client, url.c_str()))
	{ // HTTP
		Serial.print(F("[HTTP] GET...\n"));
		// start connection and send HTTP header
		int httpCode = Client1.GET();

		// httpCode will be negative on error
		if (httpCode > 0)
		{
			// HTTP header has been send and Server response header has been handled
			Serial.printf("[HTTP] GET... code:%d\n", httpCode);

			// file found at server
			if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY)
			{
				hitok = Client1.getString();
				// hitok = String(dsr) + "天" + Client1.getString();
				Serial.println(hitok);
			}
		}
		else
		{
			Serial.printf("[HTTP] GET... failed,error:%s\n", Client1.errorToString(httpCode).c_str());
		}

		Client1.end();
	}
}
/*
  draw("What a beautiful day!",SUN,27);
  draw("The sun's come out!",SUN_CLOUD,19);
  draw("It's raining cats and dogs.",RAIN,8);
  draw("That sounds like thunder.",THUNDER,12);
  draw("It's stopped raining",CLOUD,15);
*/
/*ArduinoOTA.onEnd([]()
				   {
		u8g2.clearBuffer();
		u8g2.setCursor(0,14);
		u8g2.print("[OTA]Updating Done");
		u8g2.sendBuffer();
		Serial.println("\nEnd");
		delay(3000); });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
						{
		u8g2.clearBuffer();
		u8g2.setCursor(0,14);
		u8g2.printf("[OTA]Progress:%u%%\r",(progress/(total/100)));
		u8g2.setCursor(0,30);
		u8g2.print("Don't turn off the power");
		u8g2.sendBuffer();
		Serial.printf("Progress:%u%%\r",(progress/(total/100))); });
  ArduinoOTA.onError([](ota_error_t error)
					 {
		String t;
		Serial.printf("Error[%u]:",error);
		if(error==OTA_AUTH_ERROR)
		{
			Serial.println("Auth Failed");
			t="Auth Failed";
		}
		else if(error==OTA_BEGIN_ERROR)
		{
			Serial.println("Begin Failed");
			t="Begin Failed";
		}
		else if(error==OTA_CONNECT_ERROR)
		{
			Serial.println("Connect Failed");
			t="Connect Failed";
		}
		else if(error==OTA_RECEIVE_ERROR)
		{
			Serial.println("Receive Failed");
			t="[!]Receive Failed";
		}
		else if(error==OTA_END_ERROR)
		{
			Serial.println("End Failed");
			t="[!]End Failed";
		}
		u8g2.clearBuffer();
		u8g2.setCursor(0,14);
		u8g2.print("[OTA]Error:");
		u8g2.print(t);
		u8g2.sendBuffer(); });
  // ArduinoOTA.begin();*/